package com.yanqu.road.server.cmd.cross.marriage;

import com.yanqu.road.pb.marriage.CrossMarriageProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.marriage.MarriageMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = Protocol.S_CROSS_MARRIAGE_APPOINT_REQ, desc = "跨服指向联姻请求")
public class CrossMarriageAppointReqCmd implements Command {
	@Override
	public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
		CrossMarriageProto.CrossMarriageAppointReqMsg reqMsg = CrossMarriageProto.CrossMarriageAppointReqMsg.parseFrom(packet.getBytes());
		long userId = reqMsg.getApplyData().getUserId();
		long serverId = reqMsg.getApplyData().getServerId();
		long appointUserId = packet.getPlayerId();
		int ret = MarriageMgr.checkCrossAppointMarriage(userId, serverId, appointUserId);
		CrossMarriageProto.CrossMarriageAppointRespMsg.Builder respMsg = CrossMarriageProto.CrossMarriageAppointRespMsg.newBuilder();
		respMsg.setRet(ret);
		respMsg.setApplyData(reqMsg.getApplyData());
		respMsg.setLimitEarnSpeed(reqMsg.getLimitEarnSpeed());
		YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_MARRIAGE_APPOINT_RESP, respMsg);
		GamePlayerMgr.sendPacket(appointUserId, pbMsg);
	}
}
